<!--app/views/pages/_loop_examples.html.erb-->
<h2>循环示例</h2>

<h3>1. each 循环 - 显示四季</h3>
<% @seasons.each do |season|%>
  <p><%= season %></p>
<% end %>

<h3>2. each_with_index 循环 - 带有索引index -显示星期</h3>
<% @weekdays.each_with_index do |weekday, index| %>
  <p><%= index %>: <%= weekday %></p>
<% end %>

<h3>3. each 循环 - 显示时间段</h3>
<% @time_periods.each do |period| %>
  <p><%= period[:name] %>: <%= period[:range] %></p>
<% end %>

<h3>4. times 循环 - 显示当前小时</h3>
<p>当前小时: <%= @current_hour %></p>
<p>当前小时的循环次数: <%= @current_hour.times.count %></p>
<% @current_hour.times do |i| %>
  <span><%= i + 1 %></span>
<% end %>

<h3>5. while 循环 - 倒计时</h3>
<!-- 赋值count=5 -->
<% count = 5 %>
<!-- 当 count 大于 0 时，执行循环 -->
<% while count > 0 %>
  <p>倒计时: <%= count %></p>
  <% count -= 1 %>
<% end %> 
